﻿using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;

namespace WordpressRestApi
{
    /// <summary>Client for the site API.</summary>
    /// <remarks>See https://developer.wordpress.com/docs/api/ for the endpoints available.</remarks>
    public class SiteClient : ApiClientBase
    {
        #region Inner Types
        private class PostCountPayload
        {
            [JsonProperty("counts")]
            public PostCountReportInfo Report { get; set; }
        }
        #endregion

        /// <summary>Constructor.</summary>
        /// <param name="token"></param>
        internal SiteClient(TokenInfo token)
            : base(token)
        {
        }

        /// <summary>Returns a report of the number of posts.</summary>
        /// <remarks>
        /// See https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/post-counts/%24post_type
        /// </remarks>
        /// <returns>Report.</returns>
        public async Task<PostCountReportInfo> GetPostCountsAsync()
        {
            var url = API_ROOT + "sites/" + Token.BlogID + "/post-counts/post";
            var payload = await GetRequestAsync<PostCountPayload>(url);

            return payload.Report;
        }
    }
}